package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/swapping-nodes-in-a-linked-list/description/
 * @create 2025/9/26 20:39
 * @since JDK17
 */

public class Solution69 {
    public ListNode swapNodes(ListNode head, int k) {
        ListNode dummy = new ListNode(-1, head), fast = head, slow = dummy, cur;
        for (int i = 1; i < k; i++) {
            fast = fast.next;
        }
        cur = fast;
        while (fast != null) {
            fast = fast.next;
            slow = slow.next;
        }
        int t = cur.val;
        cur.val = slow.val;
        slow.val = t;
        return head;
    }
}
